home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / MACtive Desktop / Source / Sources / FileUtils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-05-14  |  14.7 KB  |  710 lines  |  [TEXT/CWIE]

  1. #include <Errors.h>
  2. #include <Folders.h>
  3. #include <LowMem.h>
  4. #include <Script.h>
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7. #include <TextUtils.h>
  8. #include "DCon.h"
  9. #include "FileUtils.h"
  10. #include "StringUtils.h"
  11.  
  12.  
  13.  
  14.  
  15.  
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19.  
  20. typedef union UniversalFMPB
  21. {
  22.     ParamBlockRec    PB;
  23.     CInfoPBRec        ciPB;
  24.     DTPBRec            dtPB;
  25.     HParamBlockRec    hPB;
  26.     CMovePBRec        cmPB;
  27.     WDPBRec            wdPB;
  28.     FCBPBRec        fcbPB;
  29. } UniversalFMPB;
  30.  
  31. typedef struct DeleteEnumGlobals
  32. {
  33.     OSStatus        err;
  34.     Str63            itemName;
  35.     UniversalFMPB    myPB;
  36. } DeleteEnumGlobals;
  37.  
  38. static OSStatus DetermineVRefNum(StringPtr pathname,short vRefNum,short *realVRefNum);
  39. static OSStatus DeleteDirectoryContents(short vRefNum,long dirID,StringPtr name);
  40. static void DeleteLevel(long dirToDelete,DeleteEnumGlobals *theGlobals);
  41. static OSStatus GetCatInfoNoName(short vRefNum,long dirID,StringPtr name,CInfoPBPtr pb);
  42. static OSStatus GetVolumeInfoNoName(StringPtr pathname,short vRefNum,HParmBlkPtr pb);
  43.  
  44. #ifdef __cplusplus
  45. }
  46. #endif
  47.  
  48.  
  49.  
  50.  
  51.  
  52. OSStatus CreateTempDirectory(short *vRefNum,long *parID,StringPtr name,long *dirID)
  53. {
  54.     FSSpec        tmpSpec;
  55.     short        tmpVRefNum;
  56.     long        tmpParID,tmpDirID;
  57.     UInt32        secs;
  58.     OSStatus    err;
  59.     
  60.     
  61.     // Sanity check input parameters.
  62.     if_dAssertIfTrue(!vRefNum || ((!parID || !name) && !dirID))
  63.         return paramErr;
  64.     
  65.     err = FindFolder(kOnSystemDisk,kTemporaryFolderType,kCreateFolder,&tmpVRefNum,&tmpParID);
  66.     if (err != noErr)
  67.         return err;
  68.     
  69.     GetDateTime(&secs);
  70.     srand(secs);
  71.     
  72.     do
  73.     {
  74.         tmpSpec.name[0] = sprintf((char*)&tmpSpec.name[1],"tmp%08lX%04lX%04lX",secs,LMGetTicks() & 0xFFFF,rand());
  75.         err = FSMakeFSSpec(tmpVRefNum,tmpParID,tmpSpec.name,&tmpSpec);
  76.     }while(err == noErr);
  77.     if (err != fnfErr)
  78.         return err;
  79.     
  80.     err = DirCreate(tmpVRefNum,tmpParID,tmpSpec.name,&tmpDirID);
  81.     if (err != noErr)
  82.         return err;
  83.     
  84.     *vRefNum = tmpVRefNum;
  85.     if (parID) *parID = tmpParID;
  86.     if (name) pstrcpy(name,tmpSpec.name);
  87.     if (dirID) *dirID = tmpDirID;
  88.     
  89.     return noErr;
  90. }
  91.  
  92.  
  93.  
  94.  
  95.  
  96. OSStatus CreateTempFile(short *vRefNum,long *dirID,StringPtr name)
  97. {
  98.     FSSpec        tmpSpec;
  99.     short        tmpVRefNum;
  100.     long        tmpDirID;
  101.     UInt32        secs;
  102.     OSStatus    err;
  103.     
  104.     
  105.     // Sanity check input parameters.
  106.     if_dAssertIfTrue(!vRefNum || !dirID || !name)
  107.         return paramErr;
  108.     
  109.     err = FindFolder(kOnSystemDisk,kTemporaryFolderType,kCreateFolder,&tmpVRefNum,&tmpDirID);
  110.     if (err != noErr)
  111.         return err;
  112.     
  113.     GetDateTime(&secs);
  114.     srand(secs);
  115.     
  116.     do
  117.     {
  118.         tmpSpec.name[0] = sprintf((char*)&tmpSpec.name[1],"tmp%08lX%04lX%04lX",secs,LMGetTicks() & 0xFFFF,rand());
  119.         err = FSMakeFSSpec(tmpVRefNum,tmpDirID,tmpSpec.name,&tmpSpec);
  120.     }while(err == noErr);
  121.     if (err != fnfErr)
  122.         return err;
  123.     
  124.     // Create a raw file with anonymous name/type/creator.
  125.     err = HCreate(tmpVRefNum,tmpDirID,tmpSpec.name,'????','????');
  126.     if (err != noErr)
  127.         return err;
  128.     
  129.     // Make sure to create the resource fork...
  130.     HCreateResFile(tmpVRefNum,tmpDirID,tmpSpec.name);
  131.     
  132.     *vRefNum = tmpVRefNum;
  133.     *dirID = tmpDirID;
  134.     pstrcpy(name,tmpSpec.name);
  135.     
  136.     return noErr;
  137. }
  138.  
  139.  
  140.  
  141.  
  142.  
  143. OSStatus DeleteDirectory(short vRefNum,long dirID,StringPtr name)
  144. {
  145.     OSStatus    err;
  146.     
  147.     
  148.     // Sanity check input parameters.
  149.     if_dAssertIfTrue(!name)
  150.         return paramErr;
  151.     
  152.     // Make sure a directory was specified and then delete its contents.
  153.     err = DeleteDirectoryContents(vRefNum,dirID,name);
  154.     if (err == noErr)
  155.     {
  156.         err = HDelete(vRefNum,dirID,name);
  157.         if (err == fLckdErr)
  158.         {
  159.             // Unlock the directory locked by AppleShare, and try again.
  160.             HRstFLock(vRefNum,dirID,name);
  161.             err = HDelete(vRefNum,dirID,name);
  162.         }
  163.     }
  164.     
  165.     return err;
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. OSStatus DeleteDirectoryContentsFromID(short vRefNum,long dirID)
  173. {
  174.     CInfoPBRec    pb;
  175.     Str31        name;
  176.     OSStatus    err;
  177.     
  178.     
  179.     name[0] = 0;
  180.     pb.dirInfo.ioCompletion = NULL;
  181.     pb.dirInfo.ioNamePtr = name;
  182.     pb.dirInfo.ioFDirIndex = -1;    // use ioDirID
  183.     pb.dirInfo.ioVRefNum = vRefNum;
  184.     pb.dirInfo.ioDrDirID = dirID;
  185.     err = PBGetCatInfoSync(&pb);
  186.     if (err != noErr)
  187.         return err;
  188.     
  189.     return DeleteDirectoryContents(pb.dirInfo.ioVRefNum,pb.dirInfo.ioDrParID,name);
  190. }
  191.  
  192.  
  193.  
  194.  
  195.  
  196. OSStatus DeleteDirOrFile(short vRefNum,long dirID,StringPtr name)
  197. {
  198.     long        theDirID;
  199.     Boolean        isDirectory;
  200.     OSStatus    err;
  201.     
  202.     
  203.     // Sanity check input parameters.
  204.     if_dAssertIfTrue(!name)
  205.         return paramErr;
  206.     
  207.     err = GetDirectoryID(vRefNum,dirID,name,&theDirID,&isDirectory);
  208.     if (err != noErr)
  209.         return err;
  210.     
  211.     if (isDirectory)
  212.         err = DeleteDirectory(vRefNum,dirID,name);
  213.     else
  214.         err = DeleteFile(vRefNum,dirID,name);
  215.     
  216.     return err;
  217. }
  218.  
  219.  
  220.  
  221.  
  222.  
  223. OSStatus DeleteFile(short vRefNum,long dirID,StringPtr name)
  224. {
  225.     short        trashVRefNum;
  226.     long         trashDirID;
  227.     UInt32        trashSecs;
  228.     Str32        trashName;
  229.     FSSpec        trashSpec;
  230.     FIDParam    trashPB;
  231.     OSStatus    err,trashErr;
  232.     
  233.     
  234.     // Sanity check input parameters.
  235.     if_dAssertIfTrue(!name)
  236.         return paramErr;
  237.     
  238.     // Try to simply delete the file.
  239.     err = HDelete(vRefNum,dirID,name);
  240.     if (err == fLckdErr)
  241.     {
  242.         // File was locked, unlock it and try again.
  243.         HRstFLock(vRefNum,dirID,name);
  244.         err = HDelete(vRefNum,dirID,name);
  245.     }
  246.     
  247.     // Did delete fail?
  248.     if ((err != noErr) && (err != fnfErr))
  249.     {
  250.         // For one reason or another we couldn't delete the file, instead
  251.         // of blindly giving up lets try to move it to the the Trash Can.
  252.         trashErr = FindFolder(vRefNum,kTrashFolderType,kCreateFolder,&trashVRefNum,&trashDirID);
  253.         if (trashErr != noErr)
  254.             return err;
  255.         
  256.         do
  257.         {
  258.             GetDateTime(&trashSecs);
  259.             NumToString(((LMGetTicks() << 16) | (trashSecs & 0xFFFF)),trashName);
  260.             trashErr = FSMakeFSSpec(trashVRefNum,trashDirID,trashName,&trashSpec);
  261.         }while(trashErr == noErr);
  262.         
  263.         if_dAssertIfTrue(trashErr != fnfErr)
  264.             return err;
  265.         
  266.         trashErr = FSpCreate(&trashSpec,'????','????',smSystemScript);
  267.         if_dAssertIfTrue(trashErr != noErr)
  268.             return err;
  269.         
  270.         trashPB.ioCompletion = NULL;
  271.         trashPB.ioNamePtr = name;
  272.         trashPB.ioVRefNum = vRefNum;
  273.         trashPB.ioDestNamePtr = trashName;
  274.         trashPB.ioDestDirID = trashDirID;
  275.         trashPB.ioSrcDirID = dirID;
  276.         trashErr = PBExchangeFilesSync((HParmBlkPtr)&trashPB);
  277.         if (trashErr != noErr)
  278.         {
  279.             HDelete(trashVRefNum,trashDirID,trashName);
  280.             return err;
  281.         }
  282.         
  283.         err = HDelete(vRefNum,dirID,name);
  284.     }
  285.     
  286.     return err;
  287. }
  288.  
  289.  
  290.  
  291.  
  292.  
  293. OSStatus GetDirectoryID(short vRefNum,long dirID,StringPtr name,long *theDirID,Boolean *isDirectory)
  294. {
  295.     CInfoPBRec    pb;
  296.     Boolean        isDir;
  297.     OSStatus    err;
  298.     
  299.     
  300.     // Sanity check input parameters.
  301.     if_dAssertIfTrue(!name)
  302.         return paramErr;
  303.     
  304.     err = GetCatInfoNoName(vRefNum,dirID,name,&pb);
  305.     isDir = (pb.hFileInfo.ioFlAttrib & ioDirMask) != 0;
  306.     
  307.     if (isDirectory != NULL)
  308.         *isDirectory = isDir;
  309.     
  310.     if (theDirID != NULL)
  311.     {
  312.         if (isDir)
  313.             *theDirID = pb.dirInfo.ioDrDirID;
  314.         else
  315.             *theDirID = pb.hFileInfo.ioFlParID;
  316.     }
  317.     
  318.     return err;
  319. }
  320.  
  321.  
  322.  
  323.  
  324.  
  325. OSStatus GetDirOrFileVisibility(short vRefNum,long dirID,StringPtr name,Boolean *isVisible)
  326. {
  327.     CInfoPBRec    pb;
  328.     OSStatus    err;
  329.     
  330.     
  331.     // Sanity check input parameters.
  332.     if_dAssertIfTrue(!name || !isVisible)
  333.         return paramErr;
  334.     
  335.     pb.hFileInfo.ioCompletion = NULL;
  336.     pb.hFileInfo.ioNamePtr = name;
  337.     pb.hFileInfo.ioVRefNum = vRefNum;
  338.     pb.hFileInfo.ioFDirIndex = 0;
  339.     pb.hFileInfo.ioDirID = dirID;
  340.     err = PBGetCatInfoSync(&pb);
  341.     if (err != noErr)
  342.         return err;
  343.     
  344.     *isVisible = ((pb.hFileInfo.ioFlFndrInfo.fdFlags & 0x4000) == 0);
  345.     return noErr;
  346. }
  347.  
  348.  
  349.  
  350.  
  351.  
  352. OSStatus SameDirOrFile(short vRefNum1,long dirID1,StringPtr name1,short vRefNum2,long dirID2,StringPtr name2,Boolean *same)
  353. {
  354.     CInfoPBRec    pb1,pb2;
  355.     Str255        pname1,pname2;
  356.     OSStatus    err;
  357.     
  358.     
  359.     // Sanity check input parameters.
  360.     if_dAssertIfTrue(!name1 || !name2 || !same)
  361.         return paramErr;
  362.     
  363.     pb1.hFileInfo.ioCompletion = NULL;
  364.     pb1.hFileInfo.ioNamePtr = pstrcpy(pname1,name1);
  365.     pb1.hFileInfo.ioVRefNum = vRefNum1;
  366.     pb1.hFileInfo.ioFDirIndex = 0;
  367.     pb1.hFileInfo.ioDirID = dirID1;
  368.     err = PBGetCatInfoSync(&pb1);
  369.     if (err != noErr)
  370.         return err;
  371.     
  372.     pb2.hFileInfo.ioCompletion = NULL;
  373.     pb2.hFileInfo.ioNamePtr = pstrcpy(pname2,name2);
  374.     pb2.hFileInfo.ioVRefNum = vRefNum2;
  375.     pb2.hFileInfo.ioFDirIndex = 0;
  376.     pb2.hFileInfo.ioDirID = dirID2;
  377.     err = PBGetCatInfoSync(&pb2);
  378.     if (err != noErr)
  379.         return err;
  380.     
  381.     *same = ((pb1.hFileInfo.ioVRefNum == pb2.hFileInfo.ioVRefNum) &&
  382.             (pb1.hFileInfo.ioFlParID == pb2.hFileInfo.ioFlParID) &&
  383.             !pstrcmpnc(pname1,pname2));
  384.     
  385.     return noErr;
  386. }
  387.  
  388.  
  389.  
  390.  
  391.  
  392. OSStatus SetDirOrFileVisibility(short vRefNum,long dirID,StringPtr name,Boolean isVisible)
  393. {
  394.     CInfoPBRec    pb;
  395.     OSStatus    err;
  396.     
  397.     
  398.     // Sanity check input parameters.
  399.     if_dAssertIfTrue(!name)
  400.         return paramErr;
  401.     
  402.     pb.hFileInfo.ioCompletion = NULL;
  403.     pb.hFileInfo.ioNamePtr = name;
  404.     pb.hFileInfo.ioVRefNum = vRefNum;
  405.     pb.hFileInfo.ioFDirIndex = 0;
  406.     pb.hFileInfo.ioDirID = dirID;
  407.     err = PBGetCatInfoSync(&pb);
  408.     if (err != noErr)
  409.         return err;
  410.     
  411.     pb.hFileInfo.ioCompletion = NULL;
  412.     pb.hFileInfo.ioNamePtr = name;
  413.     pb.hFileInfo.ioVRefNum = vRefNum;
  414.     pb.hFileInfo.ioFDirIndex = 0;
  415.     pb.hFileInfo.ioDirID = dirID;
  416.     pb.hFileInfo.ioFlFndrInfo.fdFlags = (pb.hFileInfo.ioFlFndrInfo.fdFlags & ~0x4000) | (isVisible ? 0 : 0x4000);
  417.     err = PBSetCatInfoSync(&pb);
  418.     if (err != noErr)
  419.         return err;
  420.     
  421.     return noErr;
  422. }
  423.  
  424.  
  425.  
  426.  
  427.  
  428. OSStatus FSCreateTempDirectory(FSSpec *tmpDir,long *dirID)
  429. {
  430.     // Sanity check input parameters.
  431.     if_dAssertIfTrue(!tmpDir)
  432.         return paramErr;
  433.     
  434.     return CreateTempDirectory(&tmpDir->vRefNum,&tmpDir->parID,tmpDir->name,dirID);
  435. }
  436.  
  437.  
  438.  
  439.  
  440.  
  441. OSStatus FSCreateTempFile(FSSpec *tmpFile)
  442. {
  443.     // Sanity check input parameters.
  444.     if_dAssertIfTrue(!tmpFile)
  445.         return paramErr;
  446.     
  447.     return CreateTempFile(&tmpFile->vRefNum,&tmpFile->parID,tmpFile->name);
  448. }
  449.  
  450.  
  451.  
  452.  
  453.  
  454. OSStatus FSDeleteDirectory(FSSpec *dirSpec)
  455. {
  456.     // Sanity check input parameters.
  457.     if_dAssertIfTrue(!dirSpec)
  458.         return paramErr;
  459.     
  460.     return DeleteDirectory(dirSpec->vRefNum,dirSpec->parID,dirSpec->name);
  461. }
  462.  
  463.  
  464.  
  465.  
  466.  
  467. OSStatus FSDeleteDirOrFile(FSSpec *dirOrFileSpec)
  468. {
  469.     // Sanity check input parameters.
  470.     if_dAssertIfTrue(!dirOrFileSpec)
  471.         return paramErr;
  472.     
  473.     return DeleteDirOrFile(dirOrFileSpec->vRefNum,dirOrFileSpec->parID,dirOrFileSpec->name);
  474. }
  475.  
  476.  
  477.  
  478.  
  479.  
  480. OSStatus FSDeleteFile(FSSpec *fileSpec)
  481. {
  482.     // Sanity check input parameters.
  483.     if_dAssertIfTrue(!fileSpec)
  484.         return paramErr;
  485.     
  486.     return DeleteFile(fileSpec->vRefNum,fileSpec->parID,fileSpec->name);
  487. }
  488.  
  489.  
  490.  
  491.  
  492.  
  493. OSStatus FSGetDirectoryID(FSSpec *dirOrFileSpec,long *theDirID,Boolean *isDirectory)
  494. {
  495.     // Sanity check input parameters.
  496.     if_dAssertIfTrue(!dirOrFileSpec)
  497.         return paramErr;
  498.     
  499.     return GetDirectoryID(dirOrFileSpec->vRefNum,dirOrFileSpec->parID,dirOrFileSpec->name,theDirID,isDirectory);
  500. }
  501.  
  502.  
  503.  
  504.  
  505.  
  506. OSStatus FSGetDirOrFileVisibility(FSSpec *dirOrFileSpec,Boolean *isVisible)
  507. {
  508.     // Sanity check input parameters.
  509.     if_dAssertIfTrue(!dirOrFileSpec || !isVisible)
  510.         return paramErr;
  511.     
  512.     return GetDirOrFileVisibility(dirOrFileSpec->vRefNum,dirOrFileSpec->parID,dirOrFileSpec->name,isVisible);
  513. }
  514.  
  515.  
  516.  
  517.  
  518.  
  519. OSStatus FSSameDirOrFile(FSSpec *fileOrDir1,FSSpec *fileOrDir2,Boolean *same)
  520. {
  521.     // Sanity check input parameters.
  522.     if_dAssertIfTrue(!fileOrDir1 || !fileOrDir2 || !same)
  523.         return paramErr;
  524.     
  525.     return SameDirOrFile(fileOrDir1->vRefNum,fileOrDir1->parID,fileOrDir1->name,
  526.                     fileOrDir2->vRefNum,fileOrDir2->parID,fileOrDir2->name,same);
  527. }
  528.  
  529.  
  530.  
  531.  
  532.  
  533. OSStatus FSSetDirOrFileVisibility(FSSpec *dirOrFileSpec,Boolean isVisible)
  534. {
  535.     // Sanity check input parameters.
  536.     if_dAssertIfTrue(!dirOrFileSpec)
  537.         return paramErr;
  538.     
  539.     return SetDirOrFileVisibility(dirOrFileSpec->vRefNum,dirOrFileSpec->parID,dirOrFileSpec->name,isVisible);
  540. }
  541.  
  542.  
  543. #if 0
  544. #pragma mark -
  545. #endif
  546.  
  547.  
  548. OSStatus DetermineVRefNum(StringPtr pathname,short vRefNum,short *realVRefNum)
  549. {
  550.     HParamBlockRec    pb;
  551.     OSStatus        err;
  552.     
  553.     
  554.     err = GetVolumeInfoNoName(pathname,vRefNum,&pb);
  555.     *realVRefNum = pb.volumeParam.ioVRefNum;
  556.     return err;
  557. }
  558.  
  559.  
  560.  
  561.  
  562.  
  563. OSStatus DeleteDirectoryContents(short vRefNum,long dirID,StringPtr name)
  564. {
  565.     DeleteEnumGlobals    theGlobals;
  566.     Boolean                isDirectory;
  567.     OSStatus            err;
  568.     
  569.     
  570.     // Get the real dirID and make sure it is a directory.
  571.     err = GetDirectoryID(vRefNum,dirID,name,&dirID,&isDirectory);
  572.     if (err == noErr)
  573.     {
  574.         if (isDirectory)
  575.         {
  576.             // Get the real vRefNum.
  577.             err = DetermineVRefNum(name,vRefNum,&vRefNum);
  578.             if (err == noErr)
  579.             {
  580.                 // Set up the globals we need to access from the recursive routine.
  581.                 theGlobals.myPB.ciPB.dirInfo.ioVRefNum = vRefNum;
  582.                 
  583.                 // Here we go into recursion land...
  584.                 DeleteLevel(dirID,&theGlobals);
  585.                 err = theGlobals.err;
  586.             }
  587.         }
  588.         else
  589.         {
  590.             err = dirNFErr;
  591.         }
  592.     }
  593.     
  594.     return err;
  595. }
  596.  
  597.  
  598.  
  599.  
  600.  
  601. void DeleteLevel(long dirToDelete,DeleteEnumGlobals *theGlobals)
  602. {
  603.     long    savedDir;
  604.     
  605.     
  606.     do
  607.     {
  608.         // Prepare to delete directory.
  609.         theGlobals->myPB.ciPB.dirInfo.ioNamePtr = (StringPtr)&theGlobals->itemName;
  610.         theGlobals->myPB.ciPB.dirInfo.ioFDirIndex = 1;    // get first item
  611.         theGlobals->myPB.ciPB.dirInfo.ioDrDirID = dirToDelete;
  612.         theGlobals->err = PBGetCatInfoSync(&(theGlobals->myPB.ciPB));
  613.         if (theGlobals->err == noErr)
  614.         {
  615.             savedDir = dirToDelete;
  616.             
  617.             // We have an item.  Is it a file or directory?
  618.             if ((theGlobals->myPB.ciPB.dirInfo.ioFlAttrib & ioDirMask) != 0)
  619.             {
  620.                 // It's a directory.
  621.                 savedDir = theGlobals->myPB.ciPB.dirInfo.ioDrDirID;    // save dirID of directory instead
  622.                 DeleteLevel(theGlobals->myPB.ciPB.dirInfo.ioDrDirID,theGlobals);    // Delete its contents
  623.                 theGlobals->myPB.ciPB.dirInfo.ioNamePtr = NULL;    // prepare to delete directory
  624.             }
  625.             
  626.             if (theGlobals->err == noErr)
  627.             {
  628.                 theGlobals->myPB.ciPB.dirInfo.ioDrDirID = savedDir;    // restore dirID
  629.                 theGlobals->myPB.hPB.fileParam.ioFVersNum = 0;    // just in case it's used on an MFS volume...
  630.                 theGlobals->err = PBHDeleteSync(&(theGlobals->myPB.hPB));    // delete this item
  631.                 if (theGlobals->err != noErr)
  632.                 {
  633.                     theGlobals->err = DeleteFile(theGlobals->myPB.hPB.fileParam.ioVRefNum,
  634.                                                 theGlobals->myPB.ciPB.dirInfo.ioDrDirID,
  635.                                                 theGlobals->myPB.ciPB.dirInfo.ioNamePtr);
  636.                 }
  637.             }
  638.         }
  639.     }while(theGlobals->err == noErr);
  640.     
  641.     if (theGlobals->err == fnfErr)
  642.         theGlobals->err = noErr;
  643. }
  644.  
  645.  
  646.  
  647.  
  648.  
  649. OSStatus GetCatInfoNoName(short vRefNum,long dirID,StringPtr name,CInfoPBPtr pb)
  650. {
  651.     Str31        tempName;
  652.     OSStatus    err;
  653.     
  654.     
  655.     // Protection against File Sharing problem.
  656.     if ((name == NULL) || (name[0] == 0))
  657.     {
  658.         tempName[0] = 0;
  659.         pb->dirInfo.ioNamePtr = tempName;
  660.         pb->dirInfo.ioFDirIndex = -1;    // use ioDirID
  661.     }
  662.     else
  663.     {
  664.         pb->dirInfo.ioNamePtr = (StringPtr)name;
  665.         pb->dirInfo.ioFDirIndex = 0;    // use ioNamePtr and ioDirID
  666.     }
  667.     
  668.     pb->dirInfo.ioVRefNum = vRefNum;
  669.     pb->dirInfo.ioDrDirID = dirID;
  670.     err = PBGetCatInfoSync(pb);
  671.     pb->dirInfo.ioNamePtr = NULL;
  672.     
  673.     return err;
  674. }
  675.  
  676.  
  677.  
  678.  
  679.  
  680. OSStatus GetVolumeInfoNoName(StringPtr pathname,short vRefNum,HParmBlkPtr pb)
  681. {
  682.     Str255        tempPathname;
  683.     OSStatus    err;
  684.     
  685.     
  686.     // Make sure pb parameter is not NULL.
  687.     if (pb != NULL)
  688.     {
  689.         pb->volumeParam.ioVRefNum = vRefNum;
  690.         if (pathname == NULL)
  691.         {
  692.             pb->volumeParam.ioNamePtr = NULL;
  693.             pb->volumeParam.ioVolIndex = 0;        // use ioVRefNum only
  694.         }
  695.         else
  696.         {
  697.             BlockMoveData(pathname,tempPathname,pathname[0] + 1);    // make a copy of the string and
  698.             pb->volumeParam.ioNamePtr = (StringPtr)tempPathname;    // use the copy so original isn't trashed
  699.             pb->volumeParam.ioVolIndex = -1;    // use ioNamePtr/ioVRefNum combination
  700.         }
  701.         
  702.         err = PBHGetVInfoSync(pb);
  703.         pb->volumeParam.ioNamePtr = NULL;    // ioNamePtr may point to local    tempPathname, so don't return it
  704.     }
  705.     else
  706.         err = paramErr;
  707.     
  708.     return err;
  709. }
  710.